package com.hserver.docker.service.impl;

import com.hserver.docker.bean.Record;
import com.hserver.docker.dao.RecordMapper;
import com.hserver.docker.service.RecordService;
import top.hserver.core.ioc.annotation.Autowired;
import top.hserver.core.ioc.annotation.Bean;

import java.util.List;

@Bean
public class RecordServiceImpl implements RecordService {

    @Autowired
    private RecordMapper recordMapper;

    @Override
    public List<Record> getList(String uuid) {
        return recordMapper.createLambdaQuery().andEq(Record::getUuid,uuid).orderBy("start_time desc").select();
    }

    @Override
    public void updateImageId(String recordId, String imageId) {
        List<Record> select = recordMapper.createLambdaQuery().andEq(Record::getId, recordId).select();
        Record record = select.get(0);
        record.setImageId(imageId);
        recordMapper.updateById(record);
    }

    @Override
    public Record getById(String recordId) {
        List<Record> select = recordMapper.createLambdaQuery().andEq(Record::getId, recordId).select();
        if (select.isEmpty()){
            return null;
        }
        return select.get(0);
    }

    @Override
    public void removeId(String recordId) {
        recordMapper.deleteById(recordId);
    }
}
